<template>
  <input type="text" placeholder="输入数字" v-model="num.num1">
  <input type="text" placeholder="输入数字" v-model="num.num2"> <br>
  <p>{{"结果为:"+num.result}}</p>
  <button @click="calc('+')">加</button>
  <button @click="calc('-')">减</button>
  <button @click="calc('*')">乘</button>
  <button @click="calc('/')">除</button>
</template>
<script setup>
import {ref} from "vue";
const num = ref({
    num1: '',
    num2: '',
    result: '',
});
const calc = (op) => {
    switch (op) {
        case '+':
            num.value.result =  eval(num.value.num1 + op + num.value.num2);
            break;
        case '-':
            num.value.result = eval(num.value.num1 + op + num.value.num2);
            break;
        case '*':
            num.value.result = eval(num.value.num1 + op + num.value.num2);
            break;
        case '/':
            num.value.result = eval(num.value.num1 + op + num.value.num2);
            break;
    }
}


</script>
<style scoped>

</style>